import 'package:cunyutech_flutter_ui/src/layout/main.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'dart:ui';

class BlurWidget extends StatelessWidget {
  final double width;
  final double height;
  final Widget background;
  final Widget foreground;
  final double blur;
  final Color color;
  final bool enable;
  final ViewStyle style;
  final AlignmentGeometry alignment;
  final Decoration decoration;
  const BlurWidget({
    Key key, 
    this.width,
    this.height,
    this.enable = true,
    this.background, 
    this.foreground,
    this.blur = 6, 
    this.color, 
    this.style,
    this.alignment,
    this.decoration,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Stack(
        overflow: Overflow.clip,
        alignment: alignment ?? Alignment.center,
        children: <Widget>[
          background,
          !enable ? null : ClipRect(
            child: BackdropFilter(
              filter: ImageFilter.blur(sigmaX: blur, sigmaY: blur),
              child: Container(
                color: color,
                decoration: decoration,
                width: width,
                height: height,
              )
            )
          ),
          foreground
        ].where((item)=> item != null).toList()
      );
  }
}